package com.oauth.linkedin.server.util;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;

import com.google.code.linkedinapi.client.enumeration.NetworkUpdateType;
import com.google.code.linkedinapi.schema.Connections;
import com.google.code.linkedinapi.schema.Person;
import com.google.code.linkedinapi.schema.Update;
import com.google.code.linkedinapi.schema.Updates;
import com.oauth.linkedin.client.beans.LinkedinUser;

public class LinkedinUtil {

	public static EnumSet<NetworkUpdateType> updatesSet = EnumSet.of(
			NetworkUpdateType.STATUS_UPDATE,
			/*
			 * NetworkUpdateType.CONNECTION_UPDATE,
			 * NetworkUpdateType.JOB_UPDATE,
			 */NetworkUpdateType.PROFILE_UPDATE,
			NetworkUpdateType.RECOMMENDATION_UPDATE);

	public static List<LinkedinUser> getUsers(Connections pConnections) {
		List<LinkedinUser> users = new ArrayList<LinkedinUser>();
		if (pConnections != null) {
			for (Person person : pConnections.getPersonList()) {
				users.add(getUser(person));
			}
		}
		return users;
	}

	public static List<LinkedinUser> getUpdates(Updates pUpdates) {
		List<LinkedinUser> users = new ArrayList<LinkedinUser>();
		if (pUpdates != null) {
			for (Update update : pUpdates.getUpdateList()) {
				users.add(getUser(update.getUpdateContent().getPerson()));
				System.out.println("key=" + update.getUpdateKey());
			}
		}
		return users;
	}

	public static LinkedinUser getUser(Person profile) {
		LinkedinUser user = new LinkedinUser();
		user.setFirstName(profile.getFirstName());
		user.setLastName(profile.getLastName());
		user.setHeadLine(profile.getHeadline());
		user.setId(profile.getId());
		user.setProfileImageUrl(profile.getPictureUrl());
		user.setStatus(profile.getCurrentStatus());
		System.out.println(user);
		return user;
	}

}
